#include <iostream>
#include <algorithm>
#include <cstring>
#include <string>
#include <map>
#include <vector>

using namespace std;
using LL = long long;

int main(){
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);

    int T;
    scanf("%d", &T);
    while(T--){
        int x, y;
        scanf("%d%d", &x, &y);

        if(x > y){
            printf("%d\n", x + y);
        }else{
            printf("%d\n", y - y % x / 2);
        }
    }
    return 0;
}